<template>
    <div class="absolute top-[10px] z-10 right-[10px]" @click="handleShowSkill">
        X
    </div>
    <div class="is-show-chat-skill" :style="{ width: showSkill }">
        <div
            class="max-w-[510px] bg-white h-full p-3 min-w-[325px] w-[25%] chat-skill-width"
        >
            <h2
                class="text-left pb-[24px] pt-[6px] font-bold leading-[1.1] break-all text-[28px] text-[#7C838D] flex items-end"
            >
                <img
                    class="w-[42px] inline-block"
                    src="../../assets/images/zhuanjia.png"
                />
                <span>相关</span>
            </h2>
            <ul class="flex mt-2 flex-wrap">
                <li
                    class="tab flex-shrink-0 cursor-pointer bg-white text-gray-DEEP mb-3"
                    :class="{ 'active-category': activeTab === 0 }"
                    @click="activeTab = 0"
                >
                    推荐
                </li>
                <li
                    class="tab flex-shrink-0 cursor-pointer bg-white text-gray-DEEP mb-3"
                    :class="{ 'active-category': activeTab === 1 }"
                    @click="activeTab = 1"
                >
                    我的
                </li>
                <nuxt-link to="/skill" class="chat-skill-more">
                    <li
                        class="tab flex-shrink-0 cursor-pointer bg-white text-gray-DEEP mb-3"
                    >
                        更多
                        <i
                            class="iconfont icon-jiantouyou"
                            style="font-size: 13px"
                        />
                    </li>
                </nuxt-link>
            </ul>
            <ElScrollbar
                class="h-full v-full"
                style="height: calc(100% - 140px)"
            >
                <div class="flex flex-wrap justify-between">
                    <div
                        v-if="activeTab === 1 && !sidebarList.length"
                        @click="goto"
                        class="text-center skill-item"
                        style="border-radius: 16px"
                    >
                        <img
                            src="../../assets/images/jiahao.png"
                            style="width: 70px; height: 70px"
                        />
                        <div class="mt-2 text-[#838a95]">到广场上收藏</div>
                    </div>
                    <div
                        v-for="skill in sidebarList"
                        :key="skill.id"
                        class="bg-white text-center skill-item skill-item-online"
                        style="border-radius: 16px"
                        :class="{ 'active-skill': activeSkill === skill.id }"
                        @click="handleselected(skill)"
                    >
                        <img
                            :src="skill.image"
                            style="
                                width: 56px;
                                height: 56px;
                                border-radius: 50%;
                            "
                        />
                        <h4
                            class="truncate font-bold text-[14px] pt-[16px] pb-[8px] online-chat-skill-list-item-title"
                        >
                            {{ skill.name }}
                        </h4>
                    </div>
                    <div
                        @click="goto"
                        class="text-center hidden skill-item skill-item-online chat-skill-more-box"
                        style="border-radius: 16px"
                    >
                        <img
                            src="../../assets/images/jiahao.png"
                            style="width: 70px; height: 70px"
                        />
                        <div class="mt-2 text-[#838a95]">更多</div>
                    </div>
                </div>
            </ElScrollbar>
        </div>
    </div>
</template>
<script setup lang="ts">
import { useCollections, useRecommend } from '~/components/chat-skills/hooks'
const { list: collectionList } = useCollections()
const { list: skillList } = useRecommend()
const emits = defineEmits(['selected'])
const showSkill = ref('auto')

const handleShowSkill = () => {
    if (showSkill.value === 'auto') {
        showSkill.value = '0'
    } else {
        showSkill.value = 'auto'
    }
}
const activeSkill = ref('')
const activeTab = ref(0)
const sidebarList = computed(() => {
    if (activeTab.value === 0) {
        return skillList.value
    }
    if (activeTab.value === 1) {
        return collectionList.value
    }
    return []
})
const handleselected = (row) => {
    activeSkill.value = row?.id
    emits('selected', row)
}
const router = useRouter()
const goto = () => {
    router.push('/skill')
}
const setActiveSkill = (_id) => {
    activeSkill.value = _id
}
defineExpose({
    setActiveSkill
})
</script>
<style scoped lang="scss">
@import 'assets/styles/fix_online_css.scss';
.is-show-chat-skill {
    overflow: hidden;
    transition: 0.2s ease;
}
.tab {
    margin-right: 10px;
    padding: 0 15px;
    height: 32px;
    color: #828a95;
    background: #f8f8f8;
    line-height: 32px;
    text-align: center;
    border-radius: 6px;
    transition: all 0.4s;
}
.active-category {
    color: white;
    background: var(--el-color-primary);
}
.active-skill {
    border: 1px solid var(--el-color-primary);
}

.skill-item {
    @apply cursor-pointer;
    padding: 20px;
    height: 135px;
    margin-bottom: 10px;
    width: 48%;
    background: #f4f9fc;
    transition: 0.2s all;
    img {
        display: inline-block;
    }

    &:hover {
        background: #edf8fc;
        box-shadow: 0 8px 16px #16037514;
    }
}
</style>
